1
00:00:00,150 --> 00:00:01,920
Welcome to your final module.

2
00:00:01,920 --> 00:00:04,520
Before we start working on scripts.

3
00:00:04,980 --> 00:00:11,370
So this last module is a very important one because we have to define what sockets are.

4
00:00:11,400 --> 00:00:16,090
So we're gonna be using sockets to connect to nodes together.

5
00:00:16,230 --> 00:00:17,550
Really that's it.

6
00:00:17,550 --> 00:00:24,030
A more layman's terms what we're doing is we're going to use sockets to connect to an open port an IP

7
00:00:24,030 --> 00:00:24,870
address.

8
00:00:24,870 --> 00:00:28,020
So you're going to see this when we build a port scanner.

9
00:00:28,080 --> 00:00:32,760
You're also going to see this later on in the exploit development portion of the course where we have

10
00:00:32,760 --> 00:00:38,940
to reach out to a specific port an IP address establish a connection and send malicious data.

11
00:00:39,330 --> 00:00:45,630
So what we're going to do here is we're going to just build out a simple socket script and we're going

12
00:00:45,630 --> 00:00:50,510
to connect to an open port with that script and it'll start to make sense.

13
00:00:50,520 --> 00:00:55,170
And then when you see it in the next video when we build out the port scanner make a little bit more

14
00:00:55,170 --> 00:00:59,490
sense and you see it again in the course you're going to say hey I remember that we use sockets for

15
00:00:59,490 --> 00:01:00,940
connecting to ports.

16
00:01:00,990 --> 00:01:02,690
So here's what we're gonna do.

17
00:01:02,730 --> 00:01:06,570
We're going to make a file and call the file s dot pi.

18
00:01:06,570 --> 00:01:11,130
You can call it whatever you want just do not call it socket dot pi if you call it socket that pie you're

19
00:01:11,130 --> 00:01:15,850
going to run into issues because it's going to think it is a socket.

20
00:01:15,960 --> 00:01:20,700
So we need to define a couple of things first.

21
00:01:20,730 --> 00:01:29,690
So we're going to do is we're going to of course shebang of top do our been Python 3 and we're going

22
00:01:29,690 --> 00:01:34,040
to import socket so remember importing is important.

23
00:01:34,040 --> 00:01:36,840
We have to import socket up here at the top.

24
00:01:37,580 --> 00:01:39,650
Now let's define a couple of variables.

25
00:01:39,650 --> 00:01:46,220
So the first variable we're gonna say is host and we're just going to give that our local address here

26
00:01:46,220 --> 00:01:48,050
of 1 2 7 0 0 1.

27
00:01:48,050 --> 00:01:49,630
This is our local host.

28
00:01:49,910 --> 00:01:52,140
And we're going to define port.

29
00:01:52,190 --> 00:01:54,940
And I'm just gonna get mine all sevens.

30
00:01:55,040 --> 00:01:57,480
You can give it whatever you'd like here.

31
00:01:58,040 --> 00:02:08,910
And I'm going to define another variable like this as equals socket dot socket socket.

32
00:02:09,110 --> 00:02:17,480
Dot a f net socket dot SOC underscore string.

33
00:02:17,510 --> 00:02:20,460
Now this looks long and intimidating.

34
00:02:20,510 --> 00:02:23,050
Please do not be intimidated by this.

35
00:02:23,120 --> 00:02:26,210
We are just making our life easier on ourselves.

36
00:02:26,240 --> 00:02:30,610
So we're defining a variable that stores all this into one.

37
00:02:30,610 --> 00:02:33,440
And this is very very common when it comes to sockets.

38
00:02:33,440 --> 00:02:35,810
The syntax here is very common.

39
00:02:35,810 --> 00:02:44,130
So we're saying is hey we want s to equal socket dot socket and this socket a f iiNet socket SOC stream.

40
00:02:44,240 --> 00:02:51,040
So if iiNet just think about that as IP V for we're connecting over an IP V for connection socket that

41
00:02:51,070 --> 00:02:52,100
SOC stream.

42
00:02:52,100 --> 00:02:53,990
You could just think of this as a port.

43
00:02:54,320 --> 00:02:57,530
So I find it IPD for SOC stream.

44
00:02:57,620 --> 00:02:58,220
It's a port.

45
00:02:58,940 --> 00:03:01,450
So let's say we want to make a connection.

46
00:03:01,610 --> 00:03:04,880
We're going to say s dot connect.

47
00:03:04,880 --> 00:03:09,620
Now connect is just another part of the socket module.

48
00:03:09,620 --> 00:03:11,930
So we're going to make a connection here.

49
00:03:11,960 --> 00:03:16,480
So if you think about this we're using all this and then dot connect.

50
00:03:16,490 --> 00:03:16,790
Right.

51
00:03:16,790 --> 00:03:18,640
So we're declaring this.

52
00:03:18,650 --> 00:03:23,390
And then we have these two parameters here a socket a finite socket Sox stream.

53
00:03:23,390 --> 00:03:24,910
So the F iiNet.

54
00:03:24,920 --> 00:03:32,570
We need to say hey let's make this a our host variable and then this one our port variable and we could

55
00:03:32,570 --> 00:03:36,970
in theory just put in 7 7 7 7 and 1 2 7 0 0 1.

56
00:03:37,040 --> 00:03:41,730
But it's just easier to find those in a variable up top and then use them later to connect.

57
00:03:42,230 --> 00:03:46,760
So I'm going to go ahead and save this and then I'm going to open up a new terminal in a new window

58
00:03:46,760 --> 00:03:51,120
here and I'm going to utilize a tool that we have not used before.

59
00:03:51,410 --> 00:03:56,100
And this tool is called net cat and we'll use this later on in the course quite a bit.

60
00:03:56,150 --> 00:03:59,080
So we'll say net cat and I'm just going to say and DLP.

61
00:03:59,090 --> 00:04:06,190
This means I'm going to establish a listening port I'm going to listen on Port seven seven seven seven

62
00:04:06,520 --> 00:04:07,450
for a connection.

63
00:04:07,460 --> 00:04:12,830
So you see here it says hey we're listening on any interface for all sevens you have to worry too much

64
00:04:12,830 --> 00:04:17,840
about this right now where to go into detail on net cat at a later time but all we're doing right now

65
00:04:17,840 --> 00:04:20,360
is we're waiting for anybody to connect to us.

66
00:04:20,420 --> 00:04:25,720
Now here we're sitting at our local host of 1 2 7 0 0 1.

67
00:04:25,760 --> 00:04:29,430
So we need to establish that connection which is what we're going to do with this script.

68
00:04:29,450 --> 00:04:30,860
Now the script does nothing.

69
00:04:30,860 --> 00:04:32,840
It establishes a connection and that is it.

70
00:04:32,840 --> 00:04:41,510
So let's go ahead and take a quick look where it is going to say Python 3 s stop pi do that come over

71
00:04:41,510 --> 00:04:44,590
here and you see that we have established connection made.

72
00:04:44,590 --> 00:04:46,290
And then the connection closed.

73
00:04:46,400 --> 00:04:47,720
We didn't tell it to do anything.

74
00:04:47,720 --> 00:04:53,480
There's nothing here to say hey keep this connection open send over some data do anything at all.

75
00:04:53,660 --> 00:04:56,000
We just said hey make a connection really quick.

76
00:04:56,000 --> 00:04:56,530
And it did.

77
00:04:56,570 --> 00:05:04,190
It made a connection from 1 2 7 0 0 1 to 1 2 7 0 0 1 we connected yourselves but with this script we

78
00:05:04,190 --> 00:05:10,550
had successfully achieved what we wanted to which was to utilise sockets to connect one node to another

79
00:05:10,550 --> 00:05:12,440
node that's it.

80
00:05:12,440 --> 00:05:19,350
So we're gonna build upon this whole thing here in the next lesson we're going to build a port scanner.

81
00:05:19,460 --> 00:05:22,790
It's going to be a bad port scanner but it's still going to be a great lesson.

82
00:05:22,910 --> 00:05:27,650
So let's go ahead and just take a look at that port scanner and I'll catch it in the next video.
